package com.javasm.utils;

import java.time.Instant;
import java.time.format.DateTimeFormatter;

/**
 * @className: JavasmDateUtils
 * @description
 * @author: gfs
 * @date: 2024/7/25 17:18
 * @version: 0.1
 * @since : jdk11
 */
public class JavasmDateUtils {
    private static final DateTimeFormatter ISO_OFFSET_DATE_TIME_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

    /**
     * 将ISO 8601格式的时间字符串转换为毫秒数。
     *
     * @param iso8601String ISO 8601格式的时间字符串，例如"2024-07-02T16:00:00.000Z"
     * @return 时间的毫秒数
     */
    public static long convertIso8601ToMillis(String iso8601String) {
        Instant instant = Instant.from(ISO_OFFSET_DATE_TIME_FORMATTER.parse(iso8601String));
        return instant.toEpochMilli();
    }
    public static void main(String[] args) {
        String iso8601String = "2024-07-02T16:00:00.000Z";
        long millis = convertIso8601ToMillis(iso8601String);
        System.out.println("The time in milliseconds is: " + millis);
    }
}
